// const app = getApp();

Component({
  /**
   * 自定义组件的一个重要属性，用来定义组件的属性
   * 接收外部传递的数据，属性值监听和响应，设置默认属性值
   */
  properties: {
    // 组件的对外属性，是属性名到属性设置的映射表
    selected: {
      // 默认选中list[0]页面
      type: Number,
      value: 0,
    },
  },
  data: {
    // 组件的内部数据，和 properties 一同用于组件的渲染
    selected: 0,
    color: "#7A7E83",
    selectedColor: "#3cc51f",
    backgroundColor: "#F7F8F8",
    showTabBar: true, // 根据路由判断是否显示tabBar
    // 自定义tabBar列表
    list: [
      {
        pagePath: "/pages/index/index",
        iconPath: "/image/icon_component.png",
        selectedIconPath: "/image/icon_component_HL.png",
        text: "首页",
      },
      {
        pagePath: "/pages/home/index",
        iconPath: "/image/icon_component.png",
        selectedIconPath: "/image/icon_component_HL.png",
        text: "1 页",
      },
      {
        pagePath: "/pages/index2/index",
        iconPath: "/image/icon_API.png",
        selectedIconPath: "/image/icon_API_HL.png",
        text: "2 页",
      },
      {
        pagePath: "/pages/users/users",
        iconPath: "/image/icon_user.png",
        selectedIconPath: "/image/icon_user_HL.png",
        text: "用户信息",
      },
    ],
  },

  // 数据字段监听器，用于监听 properties
  observers: {},
  created() {},
  attached() {
    // 组件初始化完毕、进入页面节点树后
    const pages = getCurrentPages(); // 上一页的路由信息
    if (pages?.length) {
      // const { route } = pages[pages.length - 1]
      // // console.log(this.data, 123, wx, pages, route)
      // if (route && route === 'pages/my-msg/my-msg') {
      //   this.setData({showTabBar: false});
      //   console.log(route, 'route', this.data.showTabBar)
      // } else {
      //   this.setData({showTabBar: true});
      // }
    } else {
      // this.setData({showTabBar: false});
    }
  },

  methods: {
    // 方法
    imgLoadReady(e: any) {
      // console.log(this, 'this')
    },

    switchTab(e: any) {
      const data = e.currentTarget.dataset;
      const url = data.path;
      wx.switchTab({ url });
      // console.log("tabBar 点击切换", url, data);
      this.setData({
        selected: data.index,
      });
    },
  },
});
